#include"Siruri.h"
Siruri::Siruri(void)
{
    dimens=1;
    p=new char[dimens];
    if(!p)
     {
         cout<<"Eroare la alocare!"<<endl;
         exit(1);
     }
     *p='\0';
}
Siruri::Siruri(char *sir)
{
    dimens=strlen(sir) +1;
    p=new char[dimens];
    if(!p)
    {
        cout<<"Eroare la alocare"<<endl;
        exit(1);
    }
    strcpy(p,sir);
}
Siruri::Siruri(const Siruri &obiect)
{
    dimens=obiect.dimens;
    p=new char[dimens];
    if(!p)
    {
        cout<<"Eroare la alocare"<<endl;
        exit(1);
    }
    strcpy(p,obiect.p);
}
ostream &operator<<(ostream &flux, Siruri &obiect)
{
    flux<<obiect.p;
    return flux;
}
Siruri Siruri::operator=(Siruri &obiect)
{
    Siruri temp(obiect.p);
    if(obiect.dimens>dimens)
    {
        delete p;
        p = new char[obiect.dimens];
        dimens=obiect.dimens;
        if(!p)
        {
            cout<<"Eroare la alocare"<<endl;
            exit(1);
        }
    }
    strcpy(p, obiect.p);
    strcpy(temp.p,obiect.p);
    return temp;
}

Siruri Siruri::operator=(char *s)
{
    int lungime=strlen(s) + 1;
    if(dimens<lungime)
    {
        delete p;
        p=new char[lungime];
        dimens=lungime;
        if(!p)
        {
            cout<<"Eroare la alocare"<<endl;
            exit(1);
        }
    }
    strcpy(p,s);
    return *this;
}


